/*
 * @Author: fishroom
 * @Date: 2022-09-30 15:22:31
 * @LastEditTime: 2023-01-03 16:38:15
 * @FilePath: \koa\app\util\webToken.ts
 */
import jwt from "jsonwebtoken";
import config from "../config/wenToken";

function sign(data: any) {
  console.log("data", data);

  return jwt.sign(data.dataValues ? data.dataValues : data, config.jwt_key as string, {
    expiresIn: config.jwt_time,
  });
}
function verify(token: string): any {
  console.log("token", token);

  try {
    const decoded = jwt.verify(token, config.jwt_key as string);
    return {
      admin: decoded,
      error: null,
    };
  } catch (error) {
    return {
      admin: null,
      error: error,
    };
  }
}
export { sign, verify };
